package com.css.zfzx.fwsjcj.modules.quality.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformSessionUtils;
import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.commen.util.Distance;
import com.css.zfzx.fwsjcj.modules.quality.service.QualityService;
import com.css.zfzx.fwsjcj.modules.quality.vo.HouseVo;
import com.css.zfzx.fwsjcj.modules.quality.vo.QualityVo;
import com.css.zfzx.fwsjcj.modules.taskmanage.task.entity.FwTaskEntity;
import com.css.zfzx.fwsjcj.modules.taskmanage.task.service.TaskService;
import com.css.zfzx.fwsjcj.modules.taskmanage.task.vo.TaskQueryVo;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.entity.*;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.service.*;
import org.apache.commons.lang3.StringUtils;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author leon
 * @Title: QualityImpl
 * @Description: 质量检测
 * @date 2020/6/16 9:58
 */
@Service
public class QualityServiceImpl implements QualityService {
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskFromService taskFromService;
    @Autowired
    private CityTaskFormService cityTaskFormService;
    @Autowired
    private NoCityTaskFromService noCityTaskFromService;
    @Autowired
    private VillageHouseFormService villageHouseFormService;
    @Autowired
    private VillagePubHouseFormService villagePubHouseFormService;


    @Override
    public JSONObject getPage(TaskQueryVo taskQueryVo, int curPage, int pageSize) {
        return taskService.getPage(taskQueryVo, curPage, pageSize);
    }

    @Override
    public void sendQualityInspector(QualityVo qualityVo) {
        taskService.sendQualityInspector(qualityVo);
    }

    @Override
    public JSONObject getPageByUser(TaskQueryVo taskQueryVo, int curPage, int pageSize) {
        return taskService.getPageByUser(taskQueryVo, curPage, pageSize);
    }

    @Override
    public JSONObject getPage(QualityVo qualityVo, int curPage, int pageSize) {
        return taskFromService.findPage(qualityVo, curPage, pageSize);
    }

    @Transactional
    @Override
    public void qualityInspection(String id) {
        ArrayList<HouseVo> houseVos = new ArrayList<>();
        // 将四个房屋的共同数据存入VOList中，方便质检
        saveForms(houseVos, id);
        // 重复性质检
        ArrayList<Boolean> booleans = isRepeatMonitor(houseVos);
        // 分项信息质检
        subOptionMonitor(houseVos, booleans);
        // 修改任务表质检状态为：已完成
        updateTask(id);
    }

    @Override
    public Object findHouse(String type, String formId) {
        Object o = new Object();
        if (Constant.BULIDING_CITY.equals(type)) {
            o = cityTaskFormService.findCityById(formId);
        }
        if (Constant.BULIDING_NOCITY.equals(type)) {
            o = noCityTaskFromService.findNoCityById(formId);
        }
        if (Constant.BULIDING_VIllAGE.equals(type)) {
            o = villageHouseFormService.findVillageHouseById(formId);
        }
        if (Constant.BULIDING_VIllAGEPUB.equals(type)) {
            o = villagePubHouseFormService.findVillagePubHouseById(formId);
        }
        return o;
    }

    /**
     * 修改任务
     *
     * @param id
     */
    private void updateTask(String id) {
        FwTaskEntity taskEntity = taskService.findById(id);
        //任务质检状态3: 质检完成(任务下普查表都已质检)
        taskEntity.setQualityStatus(Constant.TASK_QUALITY_STATUS_OK);
        taskService.update(taskEntity);
    }

    /**
     * 分项信息质检
     *
     * @param houseVos
     * @param booleans
     */
    private void subOptionMonitor(ArrayList<HouseVo> houseVos, ArrayList<Boolean> booleans) {
        for (int i = 0; i < houseVos.size(); i++) {
            HouseVo houseVo = houseVos.get(i);
            Boolean flag = booleans.get(i);
            String fwId = houseVo.getFwId();
            String bulidingType = houseVo.getBulidingType();
            if (!flag) {
                if (Constant.BULIDING_CITY.equals(bulidingType)) {
                    FwCtiyHouseEntity ctiyHouseEntity = cityTaskFormService.findCityById(fwId);
                    // 设置建筑年代、设防烈度、层数、高度、结构类型、一般结论
                    houseVo.setBuildingTime(ctiyHouseEntity.getBuildingTime());
                    houseVo.setNowFortificationIntensity(ctiyHouseEntity.getNowFortificationIntensity());
                    houseVo.setBuildingUpNum(ctiyHouseEntity.getBuildingUpNum());
                    houseVo.setBuildingHight(ctiyHouseEntity.getBuildingHight());
                    houseVo.setStructureType(ctiyHouseEntity.getStructureType());
                    houseVo.setResult(ctiyHouseEntity.getResult());
                    // 分类别进行质检
                    qualityCheck(houseVo);
                }
                if (Constant.BULIDING_NOCITY.equals(bulidingType)) {
                    FwNoctiyHouseEntity noctiyHouseEntity = noCityTaskFromService.findNoCityById(fwId);
                    // 设置建筑年代、设防烈度、层数、高度、结构类型、一般结论
                    houseVo.setBuildingTime(noctiyHouseEntity.getBuildingTime());
                    houseVo.setNowFortificationIntensity(noctiyHouseEntity.getNowFortificationIntensity());
                    houseVo.setBuildingUpNum(noctiyHouseEntity.getBuildingUpNum());
                    houseVo.setBuildingHight(noctiyHouseEntity.getBuildingHight());
                    houseVo.setStructureType(noctiyHouseEntity.getStructureType());
                    houseVo.setResult(noctiyHouseEntity.getResult());
                    qualityCheck(houseVo);
                }
                if (Constant.BULIDING_VIllAGE.equals(bulidingType)) {
                    FwVillageHouseEntity villageHouseEntity = villageHouseFormService.findVillageHouseById(fwId);
                    // 设置建筑年代、设防烈度、层数、高度、结构类型、一般结论
                    houseVo.setBuildingTime(villageHouseEntity.getBuildingTime());
                    // 农村房屋抗震烈度 对应 居住房屋抗震设防加固情况
                    // 未设防/6度（0.05g）/7度（0.10g&0.15g）/8度（0.20g&0.30g）/9度（0.40g）
                    houseVo.setNowFortificationIntensity(villageHouseEntity.getHouseReinforceSituation());
                    houseVo.setBuildingUpNum(villageHouseEntity.getBuildingLayerNum());
                    houseVo.setBuildingHight(villageHouseEntity.getBuildingHight());
                    houseVo.setStructureType(villageHouseEntity.getStructureType());
                    houseVo.setResult(villageHouseEntity.getResult());
                    qualityCheck(houseVo);
                }
                if (Constant.BULIDING_VIllAGEPUB.equals(bulidingType)) {
                    FwVillagePubhouseEntity villagePubhouseEntity = villagePubHouseFormService.findVillagePubHouseById(fwId);
                    // 设置建筑年代、设防烈度、层数、高度、结构类型、一般结论
                    houseVo.setBuildingTime(villagePubhouseEntity.getBuildingTime());
                    houseVo.setNowFortificationIntensity(villagePubhouseEntity.getNowFortificationIntensity());
                    houseVo.setBuildingUpNum(villagePubhouseEntity.getBuildingUpNum());
                    houseVo.setBuildingHight(villagePubhouseEntity.getBuildingHight());
                    houseVo.setStructureType(villagePubhouseEntity.getStructureType());
                    houseVo.setResult(villagePubhouseEntity.getResult());
                    qualityCheck(houseVo);
                }
            }
        }
    }

    /**
     * 分项性质检
     *
     * @param fwHouseVo
     */
    private void qualityCheck(HouseVo fwHouseVo) {
        // 1.年代、抗震设防烈度、层数与高度综合判定
        StringBuilder checkForAge = checkForAge(fwHouseVo);
        // 2.结构类型、抗震设防烈度、层数与高度综合判定
        StringBuilder checkForStructureType = checkForStructureType(fwHouseVo);
        // 3.关于抗震设防烈度与初步结论结合判定
        StringBuilder checkForFortificationIntensity = checkForFortificationIntensity(fwHouseVo);
        int size = checkForAge.length() + checkForStructureType.length() + checkForFortificationIntensity.length();
        // 若字符串大小大于0，说明质检未通过，有质检原因
        if (size > 0) {
            String reason = checkForAge.append(checkForStructureType).append(checkForFortificationIntensity).toString();
            String status = "3";
            fwHouseVo.setQualityReason(reason);
            fwHouseVo.setQualityStatus(status);
            updateQuality(fwHouseVo);
        }
        if (size == 0) {
            String status = "2";
            fwHouseVo.setQualityStatus(status);
            updateQuality(fwHouseVo);
        }

    }

    /**
     * 抗震设防烈度与初步结论结合判定
     *
     * @author leon
     * @date 2020/6/18 18:39
     */
    private StringBuilder checkForFortificationIntensity(HouseVo fwHouseVo) {
         StringBuilder reason = new StringBuilder();
        String nowFortificationIntensity = fwHouseVo.getNowFortificationIntensity();
        String result = fwHouseVo.getResult();
        if ("未设防".equals(nowFortificationIntensity)) {
            if ("基本符合抗震设防要求".equals(result)) {
                reason.append("抗震设防烈度为未设防：初步结论为基本符合抗震设防要求-单独标出;");
            }
        } else {
            if ("未抗震设防".equals(result)) {
                reason.append("抗震设防烈度不为为未设防：初步结论为未抗震设防-单独标出;");
            }
        }
        return reason;
    }

    /**
     * 结构类型、抗震设防烈度、层数与高度综合判定
     *
     * @param fwHouseVo
     * @return
     */
    private StringBuilder checkForStructureType(HouseVo fwHouseVo) {
        StringBuilder reason = new StringBuilder();
        String structureType = fwHouseVo.getStructureType();
        String nowFortificationIntensity = fwHouseVo.getNowFortificationIntensity();
        Integer buildingUpNum = fwHouseVo.getBuildingUpNum();
        Integer buildingHight = fwHouseVo.getBuildingHight();
        // 钢筋混凝土
        if (StringUtils.isNotEmpty(structureType) && structureType.contains("钢筋混凝土")) {
            // 抗震设防烈度为未设防、6度
            if ("未设防".equals(nowFortificationIntensity) || "6度".equals(nowFortificationIntensity)) {
                if (buildingHight > 180 || buildingUpNum > 60) {
                    reason.append("结构类型为钢筋混凝土：抗震设防烈度为未设防、6度");
                    if (buildingHight > 180) {
                        reason.append("-高度超过180m");
                    }
                    if (buildingUpNum > 60) {
                        reason.append("-地上层数超过60层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为7度
            if ("7度".equals(nowFortificationIntensity)) {
                if (buildingHight > 150 || buildingUpNum > 50) {
                    reason.append("结构类型为钢筋混凝土：抗震设防烈度为7度");
                    if (buildingHight > 150) {
                        reason.append("-高度超过150m");
                    }
                    if (buildingUpNum > 7) {
                        reason.append("-地上层数超过60层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为8度
            if ("8度".equals(nowFortificationIntensity)) {
                if (buildingHight > 120 || buildingUpNum > 40) {
                    reason.append("结构类型为钢筋混凝土：抗震设防烈度为8度");
                    if (buildingHight > 120) {
                        reason.append("-高度超过120m");
                    }
                    if (buildingUpNum > 40) {
                        reason.append("-地上层数超过40层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为9度
            if ("9度".equals(nowFortificationIntensity)) {
                if (buildingHight > 80 || buildingUpNum > 30) {
                    reason.append("结构类型为钢筋混凝土：抗震设防烈度为9度");
                    if (buildingHight > 80) {
                        reason.append("-高度超过80m");
                    }
                    if (buildingUpNum > 30) {
                        reason.append("-地上层数超过30层");
                    }
                    reason.append(";");
                }
            }
        }
        // 木结构
        if ("木结构".equals(structureType)) {
            if (buildingUpNum > 3) {
                reason.append("结构类型为木结构：地上层数超过3层;");
            }
        }
        // 低层框架、轻钢（钢）装配式、混凝土装配式
        if ("低层框架".equals(structureType) || "轻钢（钢）装配式".equals(structureType) || "混凝土装配式".equals(structureType)) {
            if (buildingUpNum > 10) {
                reason.append("结构类型为" + structureType + "：地上层数超过10层;");
            }
        }
        // 针对土木、石、窑洞、混杂结构（砖/砌块/土/石）
        if ("土木结构".equals(structureType) || "石结构".equals(structureType)
                || "窑洞结构".equals(structureType) || "混杂结构".equals(structureType)) {
            if (buildingUpNum > 2) {
                reason.append("结构类型为" + structureType + "：地上层数超过2层;");
            }
        }
        return reason;
    }

    /**
     * 年代、抗震设防烈度、层数与高度综合判定
     * 按照年代分类质检
     *
     * @param fwHouseVo
     */
    private StringBuilder checkForAge(HouseVo fwHouseVo) {
        StringBuilder reason = new StringBuilder();
        String buildingTime = fwHouseVo.getBuildingTime();
        String nowFortificationIntensity = fwHouseVo.getNowFortificationIntensity();
        Integer buildingUpNum = fwHouseVo.getBuildingUpNum();
        Integer buildingHight = fwHouseVo.getBuildingHight();
        // 针对年代为70s以前、70s、80s的
        if ("70s以前".equals(buildingTime) || "70s".equals(buildingTime) || "80s".equals(buildingTime)) {
            // 抗震设防烈度为未设防、6度、7度
            if ("未设防".equals(nowFortificationIntensity) || "6度".equals(nowFortificationIntensity) || "7度".equals(nowFortificationIntensity)) {
                if (buildingHight > 19 || buildingUpNum > 7) {
                    reason.append("年代为70s以前、70s、80s：抗震设防烈度为未设防、6度、7度");
                    if (buildingHight > 19) {
                        reason.append("-高度超过19m");
                    }
                    if (buildingUpNum > 7) {
                        reason.append("-地上层数超过7层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为8度
            if ("8度".equals(nowFortificationIntensity)) {
                if (buildingHight > 13 || buildingUpNum > 5) {
                    reason.append("年代为70s以前、70s、80s：抗震设防烈度为8度");
                    if (buildingHight > 13) {
                        reason.append("-高度超过13m");
                    }
                    if (buildingUpNum > 5) {
                        reason.append("-地上层数超过5层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为9度
            if ("9度".equals(nowFortificationIntensity)) {
                if (buildingHight > 10 || buildingUpNum > 3) {
                    reason.append("年代为70s以前、70s、80s：抗震设防烈度为9度");
                    if (buildingHight > 10) {
                        reason.append("-高度超过10m");
                    }
                    if (buildingUpNum > 3) {
                        reason.append("-地上层数超过3层");
                    }
                    reason.append(";");
                }
            }
        }
        // 针对年代为90s、00s的
        if ("90s".equals(buildingTime) || "00s".equals(buildingTime)) {
            // 抗震设防烈度为未设防、6度
            if ("未设防".equals(nowFortificationIntensity) || "6度".equals(nowFortificationIntensity)) {
                if (buildingHight > 24 || buildingUpNum > 8) {
                    reason.append("年代为90s、00s：抗震设防烈度为未设防、6度");
                    if (buildingHight > 24) {
                        reason.append("-高度超过24m");
                    }
                    if (buildingUpNum > 8) {
                        reason.append("-地上层数超过8层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为7度
            if ("7度".equals(nowFortificationIntensity)) {
                if (buildingHight > 21 || buildingUpNum > 7) {
                    reason.append("年代为90s、00s：抗震设防烈度为7度");
                    if (buildingHight > 21) {
                        reason.append("-高度超过21m");
                    }
                    if (buildingUpNum > 7) {
                        reason.append("-地上层数超过7层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为8度
            if ("8度".equals(nowFortificationIntensity)) {
                if (buildingHight > 18 || buildingUpNum > 6) {
                    reason.append("年代为90s、00s：抗震设防烈度为8度");
                    if (buildingHight > 18) {
                        reason.append("-高度超过18m");
                    }
                    if (buildingUpNum > 6) {
                        reason.append("-地上层数超过6层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为9度
            if ("9度".equals(nowFortificationIntensity)) {
                if (buildingHight > 12 || buildingUpNum > 4) {
                    reason.append("年代为90s、00s：抗震设防烈度为9度");
                    if (buildingHight > 12) {
                        reason.append("-高度超过12m");
                    }
                    if (buildingUpNum > 4) {
                        reason.append("-地上层数超过4层");
                    }
                    reason.append(";");
                }
            }
        }
        // 针对年代为10s的
        if ("10s".equals(buildingTime)) {
            // 抗震设防烈度为未设防、6度、7度
            if ("未设防".equals(nowFortificationIntensity) || "6度".equals(nowFortificationIntensity) || "7度".equals(nowFortificationIntensity)) {
                if (buildingHight > 21 || buildingUpNum > 7) {
                    reason.append("年代为10s：抗震设防烈度为未设防、6度、7度");
                    if (buildingHight > 21) {
                        reason.append("-高度超过21m");
                    }
                    if (buildingUpNum > 7) {
                        reason.append("-地上层数超过7层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为8度
            if ("8度".equals(nowFortificationIntensity)) {
                if (buildingHight > 18 || buildingUpNum > 6) {
                    reason.append("年代为10s：抗震设防烈度为8度");
                    if (buildingHight > 18) {
                        reason.append("-高度超过18m");
                    }
                    if (buildingUpNum > 6) {
                        reason.append("-地上层数超过6层");
                    }
                    reason.append(";");
                }
            }
            // 抗震设防烈度为9度
            if ("9度".equals(nowFortificationIntensity)) {
                if (buildingHight > 12 || buildingUpNum > 4) {
                    reason.append("年代为10s：抗震设防烈度为9度");
                    if (buildingHight > 12) {
                        reason.append("-高度超过12m");
                    }
                    if (buildingUpNum > 4) {
                        reason.append("-地上层数超过4层");
                    }
                    reason.append(";");
                }
            }
        }
        return reason;
    }


    /**
     * 保存四个子表数据到VoList
     *
     * @param houseVos
     * @param id
     */
    private void saveForms(ArrayList<HouseVo> houseVos, String id) {
        // 根据任务ID获取任务下的普查list
        List<FwFormEntity> formEntityList = taskFromService.findByTaskId(id);
        for (FwFormEntity formEntity : formEntityList) {
            String formId = formEntity.getFormId();
            String bulidingType = formEntity.getBulidingType();
            if (Constant.BULIDING_CITY.equals(bulidingType)) {
                FwCtiyHouseEntity ctiyHouseEntity = cityTaskFormService.findCityById(formId);
                HouseVo houseVo = new HouseVo();
                // 存储房屋 ID、类型、经纬度、名称
                houseVo.setFwId(formId);
                houseVo.setBulidingType(bulidingType);
                houseVo.setBulidingLatitude(ctiyHouseEntity.getBulidingLatitude());
                houseVo.setBulidingLongitude(ctiyHouseEntity.getBulidingLongitude());
                houseVo.setBuildingName(ctiyHouseEntity.getBuildingName());
                houseVos.add(houseVo);
            }
            if (Constant.BULIDING_NOCITY.equals(bulidingType)) {
                FwNoctiyHouseEntity noctiyHouseEntity = noCityTaskFromService.findNoCityById(formId);
                HouseVo houseVo = new HouseVo();
                // 存储房屋 ID、类型、经纬度、名称
                houseVo.setFwId(formId);
                houseVo.setBulidingType(bulidingType);
                houseVo.setBulidingLatitude(noctiyHouseEntity.getBulidingLatitude());
                houseVo.setBulidingLongitude(noctiyHouseEntity.getBulidingLongitude());
                houseVo.setBuildingName(noctiyHouseEntity.getBuildingName());
                houseVos.add(houseVo);
            }
            if (Constant.BULIDING_VIllAGE.equals(bulidingType)) {
                FwVillageHouseEntity villageHouseEntity = villageHouseFormService.findVillageHouseById(formId);
                HouseVo houseVo = new HouseVo();
                // 存储房屋 ID、类型、经纬度、名称
                houseVo.setFwId(formId);
                houseVo.setBulidingType(bulidingType);
                houseVo.setBulidingLatitude(villageHouseEntity.getBulidingLatitude());
                houseVo.setBulidingLongitude(villageHouseEntity.getBulidingLongitude());
                houseVo.setBuildingName(villageHouseEntity.getBuildingName());
                houseVos.add(houseVo);
            }
            if (Constant.BULIDING_VIllAGEPUB.equals(bulidingType)) {
                FwVillagePubhouseEntity villagePubhouseEntity = villagePubHouseFormService.findVillagePubHouseById(formId);
                HouseVo houseVo = new HouseVo();
                // 存储房屋 ID、类型、经纬度、名称
                houseVo.setFwId(formId);
                houseVo.setBulidingType(bulidingType);
                houseVo.setBulidingLatitude(villagePubhouseEntity.getBulidingLatitude());
                houseVo.setBulidingLongitude(villagePubhouseEntity.getBulidingLongitude());
                houseVo.setBuildingName(villagePubhouseEntity.getBuildingName());
                houseVos.add(houseVo);
            }
        }
    }

    /**
     * 是否重复性质检
     *
     * @param houseVos
     * @return
     */
    private ArrayList<Boolean> isRepeatMonitor(List<HouseVo> houseVos) {
        ArrayList<Boolean> list = new ArrayList<>();
        // 将经纬度转换为GlobalCoordinates类型存入list
        ArrayList<GlobalCoordinates> coordinatesList = new ArrayList<>();
        for (HouseVo houseVo : houseVos) {
            // 经度 纬度
            double longitude = Double.parseDouble(houseVo.getBulidingLongitude());
            double latitude = Double.parseDouble(houseVo.getBulidingLatitude());
            GlobalCoordinates coordinates = new GlobalCoordinates(longitude, latitude);
            coordinatesList.add(coordinates);
        }

        for (int i = 0; i < coordinatesList.size(); i++) {
            boolean flag = false;
            for (int j = 0; j < coordinatesList.size() - i - 1; j++) {
                // 两两比较计算距离
                Double distanceMeter = Distance.getDistanceMeter(coordinatesList.get(i), coordinatesList.get(j + 1), Ellipsoid.Sphere);
                double scopeMeter = 5.0D;
                // 间隔距离5米内，并且建筑名称相同
                if (distanceMeter <= scopeMeter) {
                    HouseVo houseVoI = houseVos.get(i);
                    HouseVo houseVoJ = houseVos.get(j + 1);
                    String buildingNameI = houseVoI.getBuildingName();
                    String buildingNameJ = houseVoJ.getBuildingName();
                    // 判断建筑名称相同
                    if (StringUtils.equals(buildingNameI, buildingNameJ)) {
                        flag = true;
                        houseVoI.setQualityReason("质检存疑数据");
                        houseVoJ.setQualityReason("质检存疑数据");
                        // 3 质检失败
                        houseVoI.setQualityStatus("3");
                        houseVoJ.setQualityStatus("3");
                        updateQuality(houseVoI);
                        updateQuality(houseVoJ);
                    }
                }
            }
            list.add(flag);
        }
        return list;
    }

    /**
     * 质检更新子表字段
     *
     * @param houseVo
     */
    private void updateQuality(HouseVo houseVo) {
        String fwId = houseVo.getFwId();
        String bulidingType = houseVo.getBulidingType();
        String qualityReason = houseVo.getQualityReason();
        String qualityStatus = houseVo.getQualityStatus();

        if (Constant.BULIDING_CITY.equals(bulidingType)) {
            FwCtiyHouseEntity ctiyHouseEntity = cityTaskFormService.findCityById(fwId);
            if (!"3".equals(ctiyHouseEntity.getQualityStatus())) {
                ctiyHouseEntity.setQualityStatus(qualityStatus);
                ctiyHouseEntity.setQualityReason(qualityReason);
                cityTaskFormService.update(ctiyHouseEntity);
            }
        }
        if (Constant.BULIDING_NOCITY.equals(bulidingType)) {
            FwNoctiyHouseEntity noctiyHouseEntity = noCityTaskFromService.findNoCityById(fwId);
            if (!"3".equals(noctiyHouseEntity.getQualityStatus())) {
                noctiyHouseEntity.setQualityStatus(qualityStatus);
                noctiyHouseEntity.setQualityReason(qualityReason);
                noCityTaskFromService.update(noctiyHouseEntity);
            }
        }
        if (Constant.BULIDING_VIllAGE.equals(bulidingType)) {
            FwVillageHouseEntity villageHouseEntity = villageHouseFormService.findVillageHouseById(fwId);
            if (!"3".equals(villageHouseEntity.getQualityStatus())) {
                villageHouseEntity.setQualityStatus(qualityStatus);
                villageHouseEntity.setQualityReason(qualityReason);
                villageHouseFormService.update(villageHouseEntity);
            }
        }
        if (Constant.BULIDING_VIllAGEPUB.equals(bulidingType)) {
            FwVillagePubhouseEntity villagePubhouseEntity = villagePubHouseFormService.findVillagePubHouseById(fwId);
            if (!"3".equals(villagePubhouseEntity.getQualityStatus())) {
                villagePubhouseEntity.setQualityStatus(qualityStatus);
                villagePubhouseEntity.setQualityReason(qualityReason);
                villagePubHouseFormService.update(villagePubhouseEntity);
            }
        }
    }
}